 /**
 * 操作权限处理
 * Copyright (c) 2022 Lam
 */

import store from '@/store'
import {validPermiValue, hasPerms} from '@/utils/permissionUtil';

export default {
  inserted(el, binding, vnode) {
    const { value } = binding

    if(!validPermiValue(value)){
      console.error(`v-hasPerms label need permission values! Like v-hasPerms="['system:user:add','system:user:edit']" or v-hasPerms='system:user:add,system:user:edit'`);
      throw new Error(`请设置权限标签值(v-hasPerms)`)
    }

    if (!hasPerms(value)) {
      el.parentNode && el.parentNode.removeChild(el)
    }
  }
}
